// Create folder structure
// Date 01:40 28/11/2016
// By Ben a.k.a DreamVB

#include <iostream>
#include <Windows.h>

using namespace std;
using std::cout;
using std::endl;

void MyCreateDir(string PathName){
	int i = 0;
	int j = 0;
	string sPart = "";
	string sDir = "";

	//Append end backslash.
	if (!PathName[PathName.length() - 1] != '\\'){
		PathName += "\\";
	}

	while (i < PathName.length()){
		if (PathName[i] == '\\'){
			//The path to create
			sDir += sPart + "\\";
			//Check for folder.
			if ((GetFileAttributesA(sDir.c_str()) & FILE_ATTRIBUTE_DIRECTORY)){
				//Create folder
				CreateDirectoryA(sDir.c_str(), NULL);
			}
			//Clear parts.
			sPart.clear();
		}
		else{
			//Split the string by backslash
			sPart += PathName[i];
		}
		//INC counter
		i++;
	}
	sPart.clear();
	sDir.clear();
}

int main(int argc, char *argv[]){
	//Create the following folder.
	string FolderLoc = "C:\\FolderDemo\\First\\1\\2\\3\\4\\End";
	//Create folder
	MyCreateDir(FolderLoc);
	return 0;
}
